// CommandLineHelper Library
// =========================
// License: Microsoft Permissive License (Ms-PL) v1.1
// Author: Rhy Mednick (http://www.rhyverse.net)
// Project Site: http://www.codeplex.com/CommandLineHelper
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using NUnit.Framework;
using CommandLineHelper.Attributes;

namespace CommandLineHelper.Tests
{
    [TestFixture]
    public class ValidatePatternAttribute_Test
    {
        /// <summary>
        ///A test for IsValid (object)
        ///</summary>
        [Test]
        public void IsValid_ValidatePatternAttribute()
        {
            ValidatePatternAttribute target = new ValidatePatternAttribute();
            target.RegexPattern = @"\b[0-9]{5}(?:-[0-9]{4})?\b"; //zip code pattern
            //validate simple matches
            object value = "12345";
            bool expected = true;
            bool actual = target.IsValid(value);
            Assert.AreEqual(expected, actual, "CommandLineHelper.Attributes.ValidatePatternAttribute.IsValid did not return the expected value.");

            value = "12345-3333";
            expected = true;
            actual = target.IsValid(value);
            Assert.AreEqual(expected, actual, "CommandLineHelper.Attributes.ValidatePatternAttribute.IsValid did not return the expected value.");

            value = "123453333";
            expected = false;
            actual = target.IsValid(value);
            Assert.AreEqual(expected, actual, "CommandLineHelper.Attributes.ValidatePatternAttribute.IsValid did not return the expected value.");

            //validate no match
            value = "123";
            expected = false;
            actual = target.IsValid(value);
            Assert.AreEqual(expected, actual, "CommandLineHelper.Attributes.ValidatePatternAttribute.IsValid did not return the expected value.");

        }

        /// <summary>
        ///A test for Options
        ///</summary>
        [Test]
        public void OptionsTest()
        {
            ValidatePatternAttribute target = new ValidatePatternAttribute();

            RegexOptions val = RegexOptions.Compiled; // TODO: Assign to an appropriate value for the property
            target.Options = val;
            Assert.AreEqual(val, target.Options, "CommandLineHelper.Attributes.ValidatePatternAttribute.Options was not set correctly.");
        }

        /// <summary>
        ///A test for RegexPattern
        ///</summary>
        [Test]
        public void RegexPatternTest()
        {
            ValidatePatternAttribute target = new ValidatePatternAttribute();

            string val = null;
            target.RegexPattern = val;
            Assert.AreEqual(val, target.RegexPattern, "CommandLineHelper.Attributes.ValidatePatternAttribute.RegexPattern was not set correctly.");

            val = "Test pattern string";
            target.RegexPattern = val;
            Assert.AreEqual(val, target.RegexPattern, "CommandLineHelper.Attributes.ValidatePatternAttribute.RegexPattern was not set correctly.");

        }
    }
}
